<?php

/**
 * This is the model class for table "dede_uploads".
 *
 * The followings are the available columns in table 'dede_uploads':
 * @property integer $aid
 * @property integer $arcid
 * @property string $title
 * @property string $url
 * @property integer $mediatype
 * @property string $width
 * @property string $height
 * @property string $playtime
 * @property integer $filesize
 * @property string $uptime
 * @property integer $mid
 */
class Uploads extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Uploads the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
	/**
     * Prepares senddate, sortrank, mid ,arcrank  and
     * typeid2 ,  id attributes before performing validation.
     */
    protected function beforeValidate() {
 
        if ($this->isNewRecord) {
            // set the senddate and so on
			$this->mediatype = $this->mid = 1;
			$this->width = $this->height = $this->playtime = 0;
			$this->uptime = time();
			
        }
        return parent::beforeValidate();
    }
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'dede_uploads';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('arcid, mediatype, filesize, mid', 'numerical', 'integerOnly'=>true),
			array('title', 'length', 'max'=>60),
			array('url', 'length', 'max'=>80),
			array('width, height, playtime, uptime', 'length', 'max'=>10),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('aid, arcid, title, url, mediatype, width, height, playtime, filesize, uptime, mid', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'aid' => 'Aid',
			'arcid' => 'Arcid',
			'title' => 'Title',
			'url' => 'Url',
			'mediatype' => 'Mediatype',
			'width' => 'Width',
			'height' => 'Height',
			'playtime' => 'Playtime',
			'filesize' => 'Filesize',
			'uptime' => 'Uptime',
			'mid' => 'Mid',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('aid',$this->aid);
		$criteria->compare('arcid',$this->arcid);
		$criteria->compare('title',$this->title,true);
		$criteria->compare('url',$this->url,true);
		$criteria->compare('mediatype',$this->mediatype);
		$criteria->compare('width',$this->width,true);
		$criteria->compare('height',$this->height,true);
		$criteria->compare('playtime',$this->playtime,true);
		$criteria->compare('filesize',$this->filesize);
		$criteria->compare('uptime',$this->uptime,true);
		$criteria->compare('mid',$this->mid);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}